package com.cqupt.sendMes.utils;

import com.cqupt.sendMes.enums.HttpStatusEnum;
import lombok.Data;

import java.io.Serializable;

@Data
//@AllArgsConstructor
public class Result<T>  implements Serializable {
    private static final long serialVersionUID = 1L;
    private Boolean success;
    private int code;
    private T data;
    private String msg;
    private String errorMessage;

    public Result(){

    }

    public static <T> Result<T> createSuccessResult(T data){
        Result<T> result = new Result<>();
        result.setSuccess(Boolean.TRUE);
        result.setData(data);
        result.setCode(HttpStatusEnum.SUCCESS.getCode());
        return result;
    }
    
    public static <T> Result<T> createFailResult(int code, String errorMessage){
        Result<T> result = new Result<>();
        result.setSuccess(Boolean.FALSE);
        result.setCode(code);
        result.setErrorMessage(errorMessage);
        return result;
    }

    public Result(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    public Result(HttpStatusEnum resultCode, T data) {
        this.code = resultCode.getCode();
        this.data = data;
    }

    public boolean isSuccess() {
        return code == HttpStatusEnum.WXP_SUCCESS.getCode();
    }
}
